/**
 * @desc
 *
 * @使用场景
 *
 * @company qianmi.com
 * @Date    2017/8/21
 **/
var webpack  = require('webpack');
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');

module.exports = {
        entry: {
            index: ['babel-polyfill','./src/index.ts'],
            // print: './src/print.ts'
        },
    devtool: 'inline-source-map',
    devServer: {
         contentBase: './dist'
   },
    resolve: {
        extensions: ['.ts', '.tsx', '.js']
    },
    externals: {
        react: 'xDllContext.React',
        immutable: 'xDllContext.Immutable',
        'react-dom': 'xDllContext.ReactDom',
        'react-dom/server': 'xDllContext.ReactDOMServer',
    },
    module:{
        rules:[  {
            test: /\.less$/,
            use: [
                { loader: 'style-loader' },
                { loader: 'css-loader' },
                {
                    loader: 'less-loader',
                    options: {
                        modifyVars: {
                            '@ant-prefix': 'x-site',
                        },
                    },
                },
            ],
        },
            {
                test: /\.css$/,
                use: ExtractTextPlugin.extract({
                    fallback: 'style-loader',
                    use: 'css-loader', //'style-loader',
                }),
            },
                {
                    test: /\.tsx?$/,
                    use: [
                        {
                            loader: 'babel-loader',
                            options: {
                                babelrc: false,
                                cacheDirectory: true,
                                presets: ['es2017','react'],
                                plugins: [
                                    ['import', { libraryName: 'antd', style: true }],
                                    'transform-decorators-legacy', //required, 必须在class-properties之前！
                                    'transform-class-properties',
                                    'transform-object-rest-spread',
                                ],
                            },
                        },
                        {
                            loader: 'awesome-typescript-loader',
                            options: {
                                useBabel: true,
                                useCache: true,
                            },
                        },
                    ],
                }
            ]
    },
    plugins: [
    new CleanWebpackPlugin(['dist']),
    new HtmlWebpackPlugin({
        title: 'Development', template: 'index.ejs',
    }),
        new webpack.DefinePlugin({
            'process.env.NODE_ENV': JSON.stringify('production'),
            XSite_ENV: JSON.stringify('prod')
        })
],
    output: {
    filename: '[name].bundle.js',
        path: path.resolve(__dirname, 'dist')
}
};
